package com.yxy.f_music_server.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.yxy.f_music_server.domain.dto.VersionDTO;
import com.yxy.f_music_server.domain.po.Version;
import com.yxy.f_music_server.domain.vo.VersionVO;
import com.yxy.f_music_server.mapper.VersionMapper;
import com.yxy.f_music_server.service.VersionService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class VersionServiceImpl implements VersionService {

    private final VersionMapper versionMapper;
    public VersionServiceImpl(VersionMapper versionMapper){
        this.versionMapper = versionMapper;
    }

    /**
     * 获取版本信息
     */
    @Override
    public VersionVO getVersion() {
        Version version = versionMapper.getLatestVersion();
        return BeanUtil.copyProperties(version, VersionVO.class);
    }

    /**
     * 发布版本
     * @param versionDTO
     */
    @Override
    public void releaseVersion(VersionDTO versionDTO) {
        Version version = BeanUtil.copyProperties(versionDTO, Version.class);
        version.setReleaseDate(LocalDate.now());
        versionMapper.insertVersion(version);
    }

    /**
     * 获取版本列表
     * @return
     */
    @Override
    public List<VersionVO> list() {
        List<Version> voList = versionMapper.selectAll();
        return BeanUtil.copyToList(voList, VersionVO.class);
    }
}
